{extend name="admin/public/base" /}

{block name="content"}
<!-- Content Header (Page header) -->
<section class="content-header">
  <h1>
    配置项
    <small></small>
  </h1>
  <ol class="breadcrumb">
    <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
    <li><a href="#">用户</a></li>
    <li class="active">组列表</li>
  </ol>
</section>

<!-- Main content -->
<section class="content">

    <div class="box box-solid">
        <div class="box-header with-border">
            <a href="{:Url('admin/config/create')}" class="btn btn-default btn-flat"><i class="fa fa-plus-square"></i> 创建新配置 </a>
            <div class="pull-right">

            </div>
        </div>

        <div class="box-body">
            <div class="table-responsive">
                <table class="table table-hover">
                    <thead>
                        <tr>
                            <th width="5%">#ID</th>
                            <th width="10%">标识</th>
                            <th width="15%">名称</th>
                            <!-- <th width="20%">值</th> -->
                            <th width="15%">数据类型</th>
                            <!-- <th width="20%">备注</th> -->
                            <th width="5%">系统配置</th>
                            <th width="10%">操作</th>
                        </tr>
                    </thead>
                    <tbody>
                    {volist name="data" id="vo"}
                        <tr id = "t_{$vo.id}">
                            <td>{$vo.id}</td>
                            <td class="text-light-blue"><a href="{:url('admin/config/edit',['id'=>$vo.id])}">{$vo.key}</a></td>
                            <td>{$vo.name}</td>
                            <!-- <td class="text-green">{$vo.value}</td> -->
                            <td>
                                {switch name="vo.type"}
                                    {case value="1"}字符串{/case}
                                    {case value="2"}json{/case}
                                    {case value="3"}数字{/case}
                                {/switch}
                            </td>
                            <!-- <td class="text-muted small">{$vo.remark}</td> -->
                            <td>
                                {eq name="vo.state" value="1"}
                                    <small class="label bg-light-blue"><i class="fa fa-check"></i></small>
                                {else/}
                                    <small class="label bg-gray"><i class="fa fa-times"></i></small>
                                {/eq}
                            </td>
                            <td>
                                <div class="btn-group">
                                    <a href="{:url('admin/config/edit',['id'=>$vo.id])}" class="btn btn-default btn-xs"><i class="fa fa-edit"></i></a>
                                    <a onClick="deleteOne({$vo.id})" class="btn btn-default btn-xs"><i class="fa fa-trash-o"></i></a>
                                </div>
                            </td>
                        </tr>
                    {/volist}
                    </tbody>
                </table>
            </div>

        </div>
        <div class="box-footer">
            <div class="row">
                <div class="col-sm-6">
                
                </div>
                
                <div class="col-sm-6">
                    <div class="pull-right">
                        {$data->render()}
                    </div>
                </div>
            </div>
        </div>
    </div>

</section>
<!-- /.content -->
{/block}

{block name="js"}
<script>
    function deleteOne(id){
            swal({
                title: "确定删除这条记录吗?",
                text: "",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                closeOnConfirm: false,
                closeOnCancel: false },
            function (isConfirm) {
                if (isConfirm) {
                    $.ajax({
                        url:"{:Url('admin/config/remove')}",
                        data:{'id':id},
                        type:'post',
                        dataType:'json',
                        success: function(xhr){
                            if(xhr.code == 200){
                                swal(xhr.msg, "", "success");
                                $("#t_"+id).remove();
                            }else{
                                swal(xhr.msg, "", "error");
                            }
                        }
                    })
                } else {
                    swal("取消操作", "", "error");
                }
            });
    }
</script>
{/block}
